#pragma once
#include<iostream>
#include<memory>
#include<string>
#include<functional>
#include"Internet.hpp"

using func_t =std:: function<void()>;

class Reactor;

class Connection
{
    public:
    Connection()
    :_sockfd(-1)
    ,_events(0)
    {

    }
    void Init()
    {
      
    }
    void SetPeer(const InetAddr& peer_addr)
    {
            _peer_addr = peer_addr;
    }
    int SockfdVal()
    {
        return _sockfd;
    }
    void SetSockfd(int sockfd)
    {
        _sockfd  = sockfd;
    }
    uint32_t GetEvents()
    {
        return _events;
    }
    void SetEvents(int events)
    {
        _events = events;
    }
    virtual void  Send() = 0;
    virtual void  Receiver() = 0;
    virtual void Execpter() = 0;
    void SetOwener( Reactor* owner)
    {
        _owner = owner;
    }
    Reactor* GetOwner()
    {
        return _owner;
    }
    void AppendIn(std::string tmp)
    {
        _inbuffer += tmp;
    }
    void AppendOut(std::string tmp)
    {
        _outbuffer += tmp;
    }
    void DisCardOutString(int n)
    {
        _outbuffer.erase(0, n);
    }
    bool IsoutEmpty()
    {
        return _outbuffer.empty();
    }
    std::string& Outstring()
    {
        return _outbuffer;
    }
    std::string& InString()
    {
        return _inbuffer;
    }
    ~Connection()
    {

    }


    private:
    int _sockfd;
    std::string _inbuffer;
    std::string _outbuffer;
    InetAddr _peer_addr;

   Reactor* _owner;

    uint32_t _events;
};